package com.supplychainapi.controller;

import java.math.BigDecimal;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

/**
 * 控制层基类
 * 
 * @author maokaikai
 * @Time 2017年9月1日 下午1:54:10
 */
@RestController
public class BaseController {
	@Autowired
	public HttpServletRequest request;
	@Autowired
	public HttpServletResponse response;

	public String getAttributeParam(String key) {
		if (request.getAttribute(key) == null) {
			return "";
		}
		return request.getAttribute(key).toString();
	}

	// 元转化成分
	public String getInPayPrice(String pay_price) {
		if (StringUtils.isNotBlank(pay_price)) {
			return new BigDecimal(pay_price).multiply(new BigDecimal(100)).intValue() + "";
		}
		return "";
	}

	// 分转化成元
	public String getOutPayPrice(String pay_price) {
		if (StringUtils.isNotBlank(pay_price)) {
			return new BigDecimal(pay_price).divide(new BigDecimal(100)).toString();
		}
		return "";
	}
}
